generated from Daydreamer-riri/starter-lib
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
[docs].tsx
27 lines (20 loc) · 743 Bytes
/
[docs].tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { Params } from 'react-router-dom'
import { useLoaderData } from 'react-router-dom'
export default function Docs() {
const doc = useLoaderData() as string
return (
<div dangerouslySetInnerHTML={{ __html: doc }} />
)
}
export const Component = Docs
export const entry = 'src/pages/[docs].tsx'
export async function loader({ params }: { params: Params<string> }) {
const doc = await import(`../docs/${params.docs}.md`)
const { renderToString } = await import('react-dom/server')
const html = renderToString(<doc.default />)
return html
}
export function getStaticPaths() {
const docs = import.meta.glob('../docs/*.md')
return Object.keys(docs).map(path => path.match(/\.(\/docs\/.*)\.md$/)?.[1] ?? '')
}